<?php

namespace Proj\ResManBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

class ProjectRepository extends EntityRepository
{
    public function findByPerson($person) {
        $qb = $this->createQueryBuilder('p')
                   ->select('p')
                   ->join('p.activities', 'a')
                   ->join('a.tasks', 't')
                   ->join('t.people', 'pe')
                   ->where('pe.id = :personId')->setParameter('personId', $person->getId())
                   ->groupBy('p.id');

        return $qb->getQuery()
                  ->getResult();
    }
}